package com.yager.service.impl;

import com.yager.mapper.CollectionMapper;
import com.yager.model.Collection;
import com.yager.service.CollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class CollectionServiceImpl implements CollectionService {

    @Autowired
    private CollectionMapper collectionMapper;

    @Override
    public void addNewCollection(String userid, String houseid) {
        int count=collectionMapper.getSameCollectionCount(userid, houseid);
        if(count>0){
            System.out.println("已经收藏过了");
        }
        else{
            Collection collection=new Collection(userid,houseid);
            collectionMapper.insert(collection);
            System.out.println("已经插入新的收藏内容");
        }

    }

    @Override
    public void removeCollection(String userid, String houseid) {
        collectionMapper.delete(userid, houseid);
        System.out.println("已经删除收藏内容");
    }

    @Override
    public List<Collection> getHouseCollectionByUserId(String userid) {
        List<Collection> list=collectionMapper.selectByUserId(userid);
        return list;
    }

    @Override
    public List<Collection> getOrderCollectionByUserId(String userid) {
        List<Collection> list=collectionMapper.selectByUserId2(userid);
        return list;
    }

    @Override
    public boolean isThisCollected(String userid,String id){
        int i=collectionMapper.getSameCollectionCount(userid,id);
        if(i>0){
            return true;
        }
        else {
            return false;
        }
    }

    @Override
    public void removeCollectionByHouseId(String houseid) {
        collectionMapper.deleteByHouseId(houseid);
    }
}
